package com.example.demo.mapper;

import com.example.demo.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    // 新增用户
    @Insert("INSERT INTO users (username, password, email, role) VALUES (#{username}, #{password}, #{email}, #{role})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertUser(User user);

    // 删除用户
    @Delete("DELETE FROM users WHERE id = #{id}")
    int deleteUserById(int id);

    // 修改用户
    @Update("UPDATE users SET username = #{username}, password = #{password}, email = #{email}, role = #{role} WHERE id = #{id}")
    int updateUser(User user);

    // 查询用户
    @Select("SELECT * FROM users WHERE id = #{id}")
    User selectUserById(int id);

    // 查询所有用户
    @Select("SELECT * FROM users")
    List<User> selectAllUsers();

    @Select("SELECT * FROM users WHERE username = #{username}")
    User findByUsername(String username);

}
